home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termCall.c < prev    next >
C/C++ Source or Header  |  1995-06-17  |  3KB  |  175 lines

  1. /*
  2. **    termCall.c
  3. **
  4. **    CallInfo-compatible log file maintenance routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Some local variables. */
  13.  
  14. STATIC BPTR        CallFile;
  15. STATIC struct timeval    CallTime;
  16.  
  17.     /* CallDate():
  18.      *
  19.      *    Add the current date and time to the logfile.
  20.      */
  21.  
  22. STATIC VOID
  23. CallDate(VOID)
  24. {
  25.         /* Days of the week. */
  26.  
  27.     STATIC STRPTR CallDays[7] =
  28.     {
  29.         "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
  30.     };
  31.  
  32.         /* Months of the year. */
  33.  
  34.     STATIC STRPTR CallMonths[12] =
  35.     {
  36.         "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
  37.     };
  38.  
  39.     struct DateStamp __aligned    Date;
  40.     struct ClockData        ClockData;
  41.  
  42.         /* Obtain current date. */
  43.  
  44.     DateStamp(&Date);
  45.  
  46.         /* Convert time and date. */
  47.  
  48.     Amiga2Date((Date . ds_Days * 86400) + (Date . ds_Minute * 60) + (Date . ds_Tick / TICKS_PER_SECOND),&ClockData);
  49.  
  50.         /* Add the date line. */
  51.  
  52.     FPrintf(CallFile,"%s %s %02ld %02ld:%02ld:%02ld %ld\n",CallDays[ClockData . wday],CallMonths[ClockData . month - 1],ClockData . mday,ClockData . hour,ClockData . min,ClockData . sec,ClockData . year);
  53. }
  54.  
  55.     /* MakeCall(struct PhoneEntry *Entry):
  56.      *
  57.      *    Register a new phone call.
  58.      */
  59.  
  60. VOID __regargs
  61. MakeCall(STRPTR Name,STRPTR Number)
  62. {
  63.         /* End previous entry. */
  64.  
  65.     if(CallFile)
  66.         StopCall(FALSE);
  67.  
  68.         /* Get current system time. */
  69.  
  70.     TimeRequest -> tr_node . io_Command = TR_GETSYSTIME;
  71.  
  72.     DoIO(TimeRequest);
  73.  
  74.         /* Remember the starting time, we will need
  75.          * it later.
  76.          */
  77.  
  78.     CallTime = TimeRequest -> tr_time;
  79.  
  80.         /* Call logging enabled? */
  81.  
  82.     if(Config -> CaptureConfig -> LogCall && Config -> CaptureConfig -> CallLogFileName[0])
  83.     {
  84.             /* Open logfile for writing. */
  85.  
  86.         if(CallFile = Open(Config -> CaptureConfig -> CallLogFileName,MODE_READWRITE))
  87.         {
  88.                 /* Seek to the end of it (append). */
  89.  
  90.             if(Seek(CallFile,0,OFFSET_END) != -1)
  91.             {
  92.                     /* Add the title line. */
  93.  
  94.                 FPrintf(CallFile,"%s (%s)\n--------------------------------\nLogin:  ",Name,Number);
  95.  
  96.                     /* Make the line complete. */
  97.  
  98.                 CallDate();
  99.             }
  100.             else
  101.             {
  102.                 Close(CallFile);
  103.  
  104.                 CallFile = NULL;
  105.             }
  106.         }
  107.     }
  108. }
  109.  
  110.     /* StopCall(BYTE Finish):
  111.      *
  112.      *    End the current phone call.
  113.      */
  114.  
  115. VOID __regargs
  116. StopCall(BYTE Finish)
  117. {
  118.         /* Is a call currently being made? */
  119.  
  120.     if(CallFile)
  121.     {
  122.         struct timeval    StopTime;
  123.         BYTE        GotName;
  124.  
  125.             /* Get current system time. */
  126.  
  127.         TimeRequest -> tr_node . io_Command = TR_GETSYSTIME;
  128.  
  129.         DoIO(TimeRequest);
  130.  
  131.             /* Remember it. */
  132.  
  133.         StopTime = TimeRequest -> tr_time;
  134.  
  135.             /* Subtract the starting time from it. */
  136.  
  137.         SubTime(&StopTime,&CallTime);
  138.  
  139.             /* Add the info line. */
  140.  
  141.         if(Finish)
  142.             FPrintf(CallFile,"*** term exited before logout: ");
  143.         else
  144.             FPrintf(CallFile,"Logout: ");
  145.  
  146.             /* Make the line complete. */
  147.  
  148.         CallDate();
  149.  
  150.             /* Get the file name. */
  151.  
  152.         GotName = NameFromFH(CallFile,SharedBuffer,MAX_FILENAME_LENGTH);
  153.  
  154.             /* Add the online time. */
  155.  
  156.         FPrintf(CallFile,"Time online: %02ld:%02ld:%02ld\n\n",(StopTime . tv_secs % 86400) / 3600,(StopTime . tv_secs % 3600) / 60,StopTime . tv_secs % 60);
  157.  
  158.             /* Finis... */
  159.  
  160.         Close(CallFile);
  161.  
  162.         CallFile = NULL;
  163.  
  164.             /* Clear the `executable' bit. */
  165.  
  166.         if(GotName)
  167.         {
  168.             AddProtection(SharedBuffer,FIBF_EXECUTE);
  169.  
  170.             if(Config -> MiscConfig -> CreateIcons)
  171.                 AddIcon(SharedBuffer,FILETYPE_TEXT,TRUE);
  172.         }
  173.     }
  174. }
  175.